// ======================================================================
// Copyright (C) 2013 Hell-Prototypes. / www.hellprototypes.com
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// ======================================================================
#ifndef DEFINE_H
#define DEFINE_H
#include <QWidget>
#include <opencv2/opencv.hpp>
#include <math.h>

#define PI  3.14159265358979323846

//=============================================================================
#define mm2mil(mm)          ((double)mm * (100.0 / 2.54))
#define mil2mm(mil)         ((double)mil * 0.0254)
#define degree2angle(deg)   (deg*PI/180)
#define ONE_STEP_DISTANCE       ((double)(3.0 * 39.37)/(360.0/18.0)/8)

//#define MANUAL_MOVE_MIN_ANGLE   (PI/180.0)  //0.01 degree
#define MANUAL_MOVE_MIN_STEP        8 //step
//=============================================================================
#define STEP_OFFSET_NUM             0
#define STEPMOTOR_MAX_STEP_LIMIT    4728
//=============================================================================
#define SERVO_MIN_DEAD_ANGLE    0//(PI/180.0)

#define PICKER_IDLE_ANGLE       degree2angle(45)

#define ANGLE_PARAM_CHECK(angle) do{ \
    if(((angle) < SERVO_MIN_DEAD_ANGLE) || ((angle) > (PI - SERVO_MIN_DEAD_ANGLE))) { \
        disp_system_msg(QString("Error angle : %1: %2").arg(#angle).arg(angle)); \
        return false; \
    } \
}while(0);

#define print_double(v) qDebug("DBG - " #v " = %f", v)
#define print_int(v) qDebug("DBG - " #v " = %d", v)
//=============================================================================
#define MY_VID                  0x04B4
#define MY_PID                  0xFFFF
//=============================================================================
#define KEY_MOVE_LEFT     (Qt::Key_Left)
#define KEY_MOVE_RIGHT    (Qt::Key_Right)
#define KEY_MOVE_BACK     (Qt::Key_Up)
#define KEY_MOVE_FRONT    (Qt::Key_Down)

#define KEY_MOVE_UP       'W'
#define KEY_MOVE_DOWN     'S'
#define KEY_MOVE_CCW      'A'
#define KEY_MOVE_CW       'D'
#define KEY_MOVE_ORIGIN   (Qt::Key_Home)
//=============================================================================
#define DEFAULT_CFG_FILE_NAME "default.cfg"
//=============================================================================
using namespace cv;

typedef struct part_s
{
    double angle;
    Point center;
} part_t;
/*
typedef struct parts_cam_factor_s
{
    double factor_camera;
    double factor_real;
} parts_cam_factor_t;
*/
typedef struct detected_parts_info
{
    int parts_num;
    int parts_min_area;
    int parts_max_area;
    int parts_avr_area;
} detected_parts_info_t;

//=============================================================================
class DPoint {
public:
    inline DPoint(double _x = 0, double _y = 0) : x(_x), y(_y) {}
    double x;
    double y;
};

class iPoint {
public:
    inline iPoint(int _x = 0, int _y = 0) : x(_x), y(_y) {}
    int x;
    int y;
};

class pcb_mark_param {
public:
    inline pcb_mark_param() {}

    DPoint mark_coor;
    iPoint arm_pos;
};

#endif // DEFINE_H
